package gbench.sandbox.plot.geom;

import static gbench.common.matlib.MatlibCanvas.WHITE;
import static gbench.common.matlib.MatlibCanvas.Range.P2;
import static gbench.common.matlib.img.ImageOps.rndrgb;
import static java.lang.Math.PI;
import static java.lang.Math.cos;
import static java.lang.Math.log;
import static java.lang.Math.sin;
import static java.lang.Math.tan;

import java.util.function.Function;

import gbench.common.matlib.MatlibCanvas;
import gbench.common.matlib.MatlibCanvas.NVec;
import static gbench.common.matlib.MatlibCanvas.*;

public class JunitAlgebra {
    
    public static void plot() {
        final var matlib = new MatlibCanvas(1000);
        final var centerx = 250d;
        final var centery = 500d;
        final var affine = (Function<NVec,NVec>)(v->v.affine(50,50,500d,250));// 对数据进行拉伸
        matlib.plot(1000, 500, pen->{
            pen.setColor(WHITE);
            pen.drawLineX(x->centerx); 
            pen.drawLineY(y->centery); // 绘制坐标轴
            
            // 离散点的线条给与连续化:连续插值
            pen.setColor(RED).drawPoints(P2(-3*PI,3*PI,200).map(matlib.fx(x->1/x)).map(affine).flatMap(nvec_continuous_line2())); // 1/x 的函数
            pen.setColor(GREEN).drawPoints(P2(-3*PI,3*PI,15).map(matlib.fx(x->x)).map(affine).flatMap(nvec_continuous_line2())); // 中心线
            
            // 离散点
            pen.setColor(rndrgb()).drawPoints(P2(-PI,3*PI,100000).map(matlib.fx(x->log(x))).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-PI,PI,100000).map(matlib.fx(x->x*x*x)).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-PI,PI,100000).map(matlib.fx(x->x*x)).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-PI,PI,100000).map(matlib.fx(Math::exp)).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-2*PI,2*PI,100000).map(matlib.fx(x->sin(x))).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-4*PI,4*PI,100000).map(matlib.fx(x->tan(x))).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-4*PI,4*PI,100000).map(matlib.fx(x->1/tan(x))).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-2*PI,2*PI,100000).map(matlib.fx(x->cos(x))).map(affine));
            pen.setColor(rndrgb()).drawPoints(P2(-2*PI,2*PI,100000).map(matlib.fx(x->1d/(x*x))).map(affine));
        });
    }
    
    public static void main(String args[]) {
        plot();
    }
}
